package ru.ys.jsolver.view;

import javax.swing.*;

import Tasks.ForPrise1;
import Tasks.FromNatasha;
import Tasks.Test9x9;

import ru.ys.jsolver.interfaces.ISolveListener;
import ru.ys.jsolver.model.*;

import ru.ys.jsolver.model.ForbiddenSittuationException;
import ru.ys.jsolver.model.Board.LineType;
@SuppressWarnings("serial")
public class MainWindow extends JFrame {
	volatile Board myBoard;
	
	public MainWindow() {
		setTitle("My window");	    
		//setDefaultCloseOperation();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	    myBoard = new Board(new Test9x9());
	    BoardComponent board = new BoardComponent(myBoard);
	    getContentPane().add(board);
	    
	    (new Thread(new Runnable() {

			@Override
			public void run() {
				repaint();
				long timeBefore = System.currentTimeMillis();
				
				try {					
					myBoard.solve(new ISolveListener() {

						@Override
						public void sittuationChanged(LineType lineType,
								int index) {
							setTitle(lineType + " " + index);
							repaint();							
						}});
				} catch (ForbiddenSittuationException e) {
					System.out.println("forbidden sittuation exception");
					e.printStackTrace();
				}
				setTitle("Solved in " + (System.currentTimeMillis() - timeBefore) + " ms");
			}})).start();
	    pack();	    
	    setVisible(true);
	}

}



